﻿@using ViewRes
@model DonutMgmtSystemFoundation.Models.GeneralJsonResultModel

@{
    Layout = "~/Views/Shared/_LoginLayout.cshtml";
}

@section Pagename{ 
    @LoginStrings.ChangePassword
}

@section Script{
    <script type="text/javascript">
        $(function () {
            $("#success").hide();

            $('.ui.form').form({
                Password: {
                    identifier: 'Password',
                    rules: [
                      {
                          type: 'empty',
                          prompt: '@LoginStrings.WritePassword'
                      }
                    ]
                },
                ConfirmPassword: {
                    identifier: 'ConfirmPassword',
                    rules: [
                      {
                          type: 'match[Password]',
                          prompt: '@LoginStrings.PasswordNotMatch'
                      }
                    ]
                }
            });

            $(".ui.form").form("setting", {
                on: blur,
                onSuccess: function () {
                    var password = $("#password").val();

                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "/Login/RecoverPasswordPost",
                        data: "UserName=@ViewBag.username&Password=" + password,
                        beforeSend: function () {
                            $(".ui.error").hide();
                            $("#success").hide();
                        },
                        success: function updateFields(data) {
                            if (!data.Success) {
                                $(".ui.error").html(data.Message).show();
                            } else {
                                $("#success").html(data.Message).show();
                            }
                        }
                    });
                }
            });

        });
    </script>
}

<div class="ui one column grid">
    <div class="column">
        <div class="ui fluid form segment">
            @if(Model.Success){
                <h3 class="ui header">@LoginStrings.ChangePassword</h3>
                <div class="two fields">
                    <div class="field">
                        <label>@LoginStrings.WritePassword</label>
                        <div class="ui left input">
                            <input placeholder="" type="password" name="Password" id="password">
                        </div>
                    </div>
                    <div class="field">
                        <label>@LoginStrings.WriteConfirmPassword</label>
                        <div class="ui left input">
                            <input placeholder="" type="password" name="ConfirmPassword" id="confirmPassword">
                        </div>
                    </div>
                </div>
                <input type="button" id="send" value="@LoginStrings.ChangePassword" class="ui blue submit button">
                <div class="ui error message"></div>
                <div id="success" class="ui success message"></div>
            }
            else
            {
                <div class="ui red message">@Model.Message</div>   
            }
        </div>
    </div>
</div>
